# /usr/bin/python3

# Author: 爱编程的章老师
# @Time: 2021/1/12 0012
# E-mail: Bluesand2010@163.com
import pygame
import sys



def flip():
    '''翻转'''
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    pygame.display.set_caption("图像变换")

    img = pygame.image.load("img.jpg").convert()  # 原图
    # none_flip_img = pygame.transform.flip(img, False, False)
    # x_flip_img = pygame.transform.flip(img, True, False)  # 左右翻
    # y_flip_img = pygame.transform.flip(img, False, True)  # 左右翻
    both_flip_img = pygame.transform.flip(img, True, True)  # 左右翻
    width = img.get_width()  # 获取img的宽度


    screen.blit(img, (0, 0))
    # screen.blit(x_flip_img, (width, 0))
    # screen.blit(y_flip_img, (width * 2, 0))
    screen.blit(both_flip_img, (width, 0))

    pygame.display.update()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()


def rotate():
    '''旋转'''
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    pygame.display.set_caption("图像变换")

    img = pygame.image.load("img.jpg").convert()  # 原图
    new_img1 = pygame.transform.rotate(img, 90) # 逆时针90度
    new_img2 = pygame.transform.rotate(img, -90) # 顺时针90度
    width = img.get_width()  # 获取img的宽度
    screen.blit(img, (0, 0))
    screen.blit(new_img1, (width, 0))
    screen.blit(new_img2, (width, width))

    pygame.display.update()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

def scale():
    '''放缩'''
    pygame.init()
    screen = pygame.display.set_mode((1000, 800))
    pygame.display.set_caption("图像变换")

    img = pygame.image.load("img.jpg").convert()  # 原图
    
    width = img.get_width()  # 获取img的宽度
    height = img.get_height() # 获取img的高度
    new_img = pygame.transform.scale(img,(width // 2, height // 2))
    two_img = pygame.transform.scale2x(img)
    smooth_img = pygame.transform.smoothscale(img, (width * 2, height * 2))


    screen.blit(two_img, (0, 0))
    screen.blit(smooth_img, (width * 2, 0))

    pygame.display.update()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()


def rotate_scale():
    '''旋转同时放缩'''
    pygame.init()
    screen = pygame.display.set_mode((1000, 800))
    pygame.display.set_caption("图像变换")
    img = pygame.image.load("img.jpg").convert()  # 原图
    new_img = pygame.transform.rotozoom(img, 60, 0.5)
    screen.blit(new_img, (0, 0))
    pygame.display.update()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

def chop():
    '''裁剪'''
    pygame.init()
    screen = pygame.display.set_mode((1000, 800))
    pygame.display.set_caption("图像变换")
    img = pygame.image.load("img.jpg").convert()  # 原图
    width = img.get_width()//2
    height = img.get_height()//2
    left = width
    top = height
    print(width, height)
    # rect = pygame.Rect(-width, 0, width, height)
    new_img = pygame.transform.chop(img, (100,121, 111, 222))

    screen.blit(img, (0, 0))
    screen.blit(new_img, (260, 0))
    pygame.display.update()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()



if __name__ == '__main__':
    chop()